package com.probiz.estoresa.other.web.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.core.controller.BaseController;
import com.probiz.estore.customer.service.ConsultManager;
import com.probiz.estore.customer.service.FeedbackManager;
import com.probiz.estore.inventory.service.InventoryManager;
import com.probiz.estore.order.service.SalesOrderManager;
import com.probiz.estore.product.service.StockNotifyManager;

/**
 * 
 * 后台头部系统提示信息
 * @author pengzhirong
 *
 * @since 3.5
 */
public class SiteMessageController extends BaseController {
	
	SalesOrderManager salesOrderManager = null;
	ConsultManager consultManager = null;
	InventoryManager inventoryManager = null;
	
	
	public void setSalesOrderManager(SalesOrderManager salesOrderManager) {
		this.salesOrderManager = salesOrderManager;
	}

	public void setConsultManager(ConsultManager consultManager) {
		this.consultManager = consultManager;
	}

	public void setInventoryManager(InventoryManager inventoryManager) {
		this.inventoryManager = inventoryManager;
	}

	/**
	 * 一次获取所有信息
	 * @return
	 */
	public ModelAndView defaultAction(HttpServletRequest request, HttpServletResponse response){
		Map<String, Long> data = new HashMap<String, Long>();
		
		Long newArrivalOrder = salesOrderManager.countNewArrivalOrder();
		data.put("newArrivalOrder", newArrivalOrder);
		//data.put("lackStockProductSkuTotal", inventoryManager.countLackStockProductSkuTotal());
		Long lowStockProductSkuTotal = inventoryManager.countLowStockProductSkuTotal();
		data.put("lowStockProductSkuTotal", lowStockProductSkuTotal);
		//data.put("uninformStockNotifyTotal", stockNotifyManager.countUninformStockNotifyTotal());
		
		Long unreplyConsultTotal = consultManager.countUnreplyConsultTotal();
		data.put("unreplyConsultTotal", unreplyConsultTotal);
		//data.put("unreplyFeedbackTotal", feedbackManager.countUnreplyFeedbackTotal());
		
		//封装上次读取的数据，形成对比，看新的数据有没有增加数量，以便在页面展示不同效果
		Long oldNewArrivalOrder = (Long)request.getSession().getAttribute("oldNewArrivalOrder");
		if(oldNewArrivalOrder==null) oldNewArrivalOrder = 0L;
		data.put("oldNewArrivalOrder", oldNewArrivalOrder);
		request.getSession(true).setAttribute("oldNewArrivalOrder", newArrivalOrder);
		
		Long oldLowStockProductSkuTotal = (Long)request.getSession().getAttribute("oldLowStockProductSkuTotal");
		if(oldLowStockProductSkuTotal==null) oldLowStockProductSkuTotal = 0L;
		data.put("oldLowStockProductSkuTotal", oldLowStockProductSkuTotal);
		request.getSession(true).setAttribute("oldLowStockProductSkuTotal", lowStockProductSkuTotal);
		
		Long oldUnreplyConsultTotal = (Long)request.getSession().getAttribute("oldUnreplyConsultTotal");
		if(oldUnreplyConsultTotal==null) oldUnreplyConsultTotal = 0L;
		data.put("oldUnreplyConsultTotal", oldUnreplyConsultTotal);
		request.getSession(true).setAttribute("oldUnreplyConsultTotal", unreplyConsultTotal);
		
		return this.getModelAndAjaxJsonView(data);
	}
	
	/**
	 * 单独获取订单信息，如果权限细化，需单独调用
	 * @return
	 */
	public ModelAndView getOrderMessage(){
		//salesOrderManager.countNewArrivalOrder();
		return null;
	}
	
}
